package main

import (
	"bbq/client/clientLog"
	"bbq/common"
	"bbq/common/protocol/remoteCommand"
	"bbq/common/protocol/request"
	"bbq/common/remoting"
	"encoding/json"
	"fmt"
	"time"
)

/*
 模拟客户端
*/
func main() {
	client := remoting.NewGnetRemoteClient(clientLog.Log)
	client.Start()

	command := mockCmd()

	resp := client.InvokeSync("127.0.0.1:10000", command, 10*time.Second)
	fmt.Println(resp)

	ch := make(chan int, 1)
	<-ch
}

func mockCmd() *remoteCommand.RemoteCommand {
	r := &request.RegisterBrokerRequest{
		"broker-a",
		"127.0.0.1:10086",
		"cluster-a",
		"127.0.0.1:10087",
		0,
		map[string]common.TopicConfig{
			"topic1": {
				"topic1",
				8,
			},
			"topic2": {
				"topic2",
				16,
			},
		},
		1,
	}

	body, _ := json.Marshal(r)

	//发送封包的message消息
	cmd := &remoteCommand.RemoteCommand{
		&remoteCommand.CmdHeader{
			Code:     remoteCommand.REGISTER_BROKER,
			Version:  int8(1),
			Opaque:   int64(2),
			ClientId: "3",
			Flag:     0,
		},
		body,
	}
	return cmd
}
